🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6258

Linker Error

#6258
From: Patrick Wong
Date: Tue, 31 May 2005 11:26
80 lines
2961 bytes
Dear all,

I try to call some Winsock APIs in a thread of my application.  It fails to
be built for:

[Linker Error] Unresolved external 'WSAIoctl' referenced from
D:\PROJECTS\SNIFFER\SNIFFERTHREAD.OBJ

Excerpt of the thread code:

int __fastcall TSnifferThread::InitSocket(void)
{
  WSAData          *pwsaData;
  int               rcvtimeo;
  char              host[50];
  struct hostent   *phostent;
  int               addr;
  char             *ip;
  sockaddr_in       sa;
  DWORD             dwBufferInLen, dwBytesReturned, dwBufferLen;

  int result = -1;

  WSAStartup(MAKEWORD(2, 2), pwsaData);   /* Initialize socket           */
  RawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_IP); /* Create SOCK_RAW type
socket */

  if(RawSocket == (Word)INVALID_SOCKET)
  {
    // Do something;
  }

  rcvtimeo = 5000;     /* Set timeout for socket creation */
  result = setsockopt(RawSocket, SOL_SOCKET, SO_RCVTIMEO, (char
*)(&rcvtimeo), sizeof(rcvtimeo));

  if(result == SOCKET_ERROR)
  {
    // Do something;
  }

  gethostname(host, sizeof(host));
  phostent = gethostbyname(host);
  ip       = phostent->h_addr_list[0];  /* obtain the local IP */

  sa.sin_family      = AF_INET;
  sa.sin_port        = htons(7000);
  sa.sin_addr.s_addr = inet_addr(ip);

  result = bind(RawSocket, (struct sockaddr *)&sa, sizeof(sa)); /* Bind
socket         */

  if(result == SOCKET_ERROR)
  {
    // Do something;
  }

  /* Use SIO_RCVALL to enable the socket to receive all IP packets on the
network */
  result = WSAIoctl(RawSocket, SIO_RCVALL, &dwBufferInLen,
                    sizeof(dwBufferInLen), &dwBufferLen,
sizeof(dwBufferLen),
                    &dwBytesReturned , NULL , NULL);

  if(result == SOCKET_ERROR)
  {
    // Do something;
  }

  result = S_OK;

  return result;
}

Comment out the call to WSAIoctl() will eliminate the problem.  Winsock
should be dynamic linking, so why the link time error will be caused?  And
why not other call like WSAStartup() causing the same problem?

Thanks in advance for your help.
Patrick
Technical Details
Message-ID: <429c49e7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e1ea2972d73d7675,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Patrick Wong" <patrickwong@computer.org>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Linker Error
Date: Tue, 31 May 2005 19:26:31 +0800
Lines: 82
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 203.82.252.252
Message-ID: <429c49e7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117538791 203.82.252.252 (31 May 2005 04:26:31 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail