Re: raw socket bind problem

Giganews Newsgroups
Subject: Re: raw socket bind problem
Posted by:  Phil Frisbie, Jr (ph…@hawksoft.com)
Date: Thu, 30 Sep 2004

Sherman wrote:
> I got a problem in binding a raw socket to local tcp port.
> The following is the code snippet and it return ERROR
> after bind() call? Anybody has any idea? Thanks,

And the error set is...? Have you checked WSAGetLastError()?

> - Sherman
>
>     if ( nRet = WSAStartup(0x0202, &stWSAData) ) {
>         printf ("WSAStartup failed: %d\r
", nRet);
>         return ERROR;
>     }
>
>        if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) {
>             return ERROR;
>        }
>
>        memset(& sin, 0, sizeof(sin));
>        sin.sin_port = htons(local_port);
>
>        if((bind(sock, (struct sockaddr *)& sin, sizeof(sin))) < 0) {
>             return ERROR;
>        }

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Replies

In response to

raw socket bind problem posted by Sherman on 30 Sep 2004