raw socket bind problem

Giganews Newsgroups
Subject: raw socket bind problem
Posted by:  Sherman (aldernetwor…@gmail.com)
Date: 30 Sep 2004

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,

- 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;
      }

Replies