2 * WSOCK32 specific functions
4 * Copyright (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
8 /* FIXME: This hack is fixing a problem in WsControl. When we call socket(),
9 * it will call into ws2_32's WSOCK32_socket (because of the redirection in
10 * our own .spec file).
11 * The problem is that socket() is predefined in a linux system header that
12 * we are including, which is different from the WINE definition.
13 * (cdecl vs. stdapi). The result is stack corruption.
14 * Furthermore WsControl uses Unix macros and types. This forces us to include
15 * the Unix headers which then conflict with the winsock headers. This forces
16 * us to use USE_WS_PREFIX but then ioctlsocket is called WS_ioctlsocket,
17 * which causes link problems. The correct solution is to implement
18 * WsControl using calls to WSAIoctl. Then we should no longer need to use the
19 * Unix headers. This would also have the advantage of reducing code
21 * Until that happens we need this ugly hack.
25 #define socket linux_socket
26 #define recv linux_recv
38 #include <sys/ioctl.h>
40 #include <sys/types.h>
41 #ifdef HAVE_SYS_SOCKET_H
42 #include <sys/socket.h>
44 #ifdef HAVE_SYS_SOCKIO_H
45 # include <sys/sockio.h>
53 #include "debugtools.h"
56 #include "wscontrol.h"
58 /* FIXME: The rest of the socket() cdecl<->stdapi stack corruption problem
63 extern SOCKET WINAPI socket(INT af, INT type, INT protocol);
64 extern SOCKET WINAPI recv(SOCKET,char*,int,int);
65 /* Plus some missing prototypes, due to the WS_ prefixing */
66 extern int WINAPI closesocket(SOCKET);
67 extern int WINAPI ioctlsocket(SOCKET,long,u_long*);
71 DEFAULT_DEBUG_CHANNEL(winsock);
74 /***********************************************************************
75 * WsControl (WSOCK32.1001)
77 * WsControl seems to be an undocumented Win95 function. A lot of
78 * discussion about WsControl can be found on the net, e.g.
79 * Subject: Re: WSOCK32.DLL WsControl Exported Function
80 * From: "Peter Rindfuss" <rindfuss-s@medea.wz-berlin.de>
83 * WSCNTL_TCPIP_QUERY_INFO option is partially implemeted based
84 * on observing the behaviour of WsControl with an app in
85 * Windows 98. It is not fully implemented, and there could
86 * be (are?) errors due to incorrect assumptions made.
89 * WsControl returns WSCTL_SUCCESS on success.
90 * STATUS_BUFFER_TOO_SMALL is returned if the output buffer length
91 * (*pcbResponseInfoLen) is too small, otherwise errors return -1.
93 * It doesn't seem to generate errors that can be retrieved by
98 DWORD WINAPI WsControl(DWORD protocoll,
101 LPDWORD pcbRequestInfoLen,
102 LPVOID pResponseInfo,
103 LPDWORD pcbResponseInfoLen)
105 /* Get the command structure into a pointer we can use,
107 TDIObjectID *pcommand = (TDIObjectID *)pRequestInfo;
109 TRACE (" WsControl TOI_ID=>0x%lx<, {TEI_ENTITY=0x%lx, TEI_INSTANCE=0x%lx}, TOI_CLASS=0x%lx, TOI_TYPE=0x%lx\n",
110 pcommand->toi_id, pcommand->toi_entity.tei_entity, pcommand->toi_entity.tei_instance,
111 pcommand->toi_class, pcommand->toi_type );
117 case WSCNTL_TCPIP_QUERY_INFO:
119 switch (pcommand->toi_id)
122 ENTITY_LIST_ID seems to get number of adapters in the system.
123 (almost like an index to be used when calling other WsControl options)
127 TDIEntityID *baseptr = pResponseInfo;
130 if (pcommand->toi_class != INFO_CLASS_GENERIC &&
131 pcommand->toi_type != INFO_TYPE_PROVIDER)
133 FIXME ("Unexpected Option for ENTITY_LIST_ID request -> toi_class=0x%lx, toi_type=0x%lx\n",
134 pcommand->toi_class, pcommand->toi_type);
135 return (WSAEOPNOTSUPP);
138 numInt = WSCNTL_GetEntryCount(WSCNTL_COUNT_INTERFACES);
141 ERR ("Unable to open /proc filesystem to determine number of network interfaces!\n");
145 if (*pcbResponseInfoLen < sizeof(TDIEntityID)*(numInt*2) )
147 return (STATUS_BUFFER_TOO_SMALL);
151 memset(baseptr, 0, sizeof(TDIEntityID)*(numInt*2));
153 for (i=0; i<numInt; i++)
155 /* tei_instance is an network interface identifier.
156 I'm not quite sure what the difference is between tei_entity values of
157 CL_NL_ENTITY and IF_ENTITY */
158 baseptr->tei_entity = CL_NL_ENTITY; baseptr->tei_instance = i; baseptr++;
159 baseptr->tei_entity = IF_ENTITY; baseptr->tei_instance = i; baseptr++;
162 /* Calculate size of out buffer */
163 *pcbResponseInfoLen = sizeof(TDIEntityID)*(numInt*2);
169 /* ENTITY_TYPE_ID is used to obtain simple information about a
170 network card, such as MAC Address, description, interface type,
171 number of network addresses, etc. */
172 case ENTITY_TYPE_ID: /* ALSO: IP_MIB_STATS_ID */
174 if (pcommand->toi_class == INFO_CLASS_GENERIC && pcommand->toi_type == INFO_TYPE_PROVIDER)
176 if (pcommand->toi_entity.tei_entity == IF_ENTITY)
178 * ((ULONG *)pResponseInfo) = IF_MIB;
180 /* Calculate size of out buffer */
181 *pcbResponseInfoLen = sizeof (ULONG);
184 else if (pcommand->toi_entity.tei_entity == CL_NL_ENTITY)
186 * ((ULONG *)pResponseInfo) = CL_NL_IP;
188 /* Calculate size of out buffer */
189 *pcbResponseInfoLen = sizeof (ULONG);
192 else if (pcommand->toi_class == INFO_CLASS_PROTOCOL &&
193 pcommand->toi_type == INFO_TYPE_PROVIDER)
195 if (pcommand->toi_entity.tei_entity == IF_ENTITY)
197 /* In this case, we are requesting specific information about a
198 a particular network adapter. (MAC Address, speed, data transmitted/received,
201 IFEntry *IntInfo = (IFEntry *) pResponseInfo;
207 if (!WSCNTL_GetInterfaceName(pcommand->toi_entity.tei_instance, ifName))
209 ERR ("Unable to parse /proc filesystem!\n");
213 /* Get a socket so that we can use ioctl */
214 if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
216 ERR ("Error creating socket!\n");
220 /* 0 out return structure first */
221 memset (IntInfo, 0, sizeof(IFEntry));
224 IntInfo->if_index = pcommand->toi_entity.tei_instance;
226 /* MAC Address - Let's try to do this in a cross-platform way... */
227 #if defined(SIOCGIFHWADDR) /* Linux */
228 strcpy(ifInfo.ifr_name, ifName);
229 if (ioctlsocket(sock, SIOCGIFHWADDR, (ULONG*)&ifInfo) < 0)
231 ERR ("Error obtaining MAC Address!\n");
237 /* FIXME: Is it correct to assume size of 6? */
238 memcpy(IntInfo->if_physaddr, ifInfo.ifr_hwaddr.sa_data, 6);
239 IntInfo->if_physaddrlen=6;
241 #elif defined(SIOCGENADDR) /* Solaris */
242 if (ioctlsocket(sock, SIOCGENADDR, (ULONG*)&ifInfo) < 0)
244 ERR ("Error obtaining MAC Address!\n");
250 /* FIXME: Is it correct to assume size of 6? */
251 memcpy(IntInfo->if_physaddr, ifInfo.ifr_enaddr, 6);
252 IntInfo->if_physaddrlen=6;
255 memset (IntInfo->if_physaddr, 0, 6);
256 ERR ("Unable to determine MAC Address on your platform!\n");
260 /* Interface name and length */
261 strcpy (IntInfo->if_descr, ifName);
262 IntInfo->if_descrlen= strlen (IntInfo->if_descr);
264 /* Obtain bytes transmitted/received for interface */
265 if ( (WSCNTL_GetTransRecvStat(pcommand->toi_entity.tei_instance,
266 &IntInfo->if_inoctets, &IntInfo->if_outoctets)) < 0)
268 ERR ("Error obtaining transmit/receive stats for the network interface!\n");
274 /* FIXME: How should the below be properly calculated? ******************/
275 IntInfo->if_type = 0x6; /* Ethernet (?) */
276 IntInfo->if_speed = 1000000; /* Speed of interface (bits per second?) */
277 /************************************************************************/
280 *pcbResponseInfoLen = sizeof (IFEntry) + IntInfo->if_descrlen;
282 else if (pcommand->toi_entity.tei_entity == CL_NL_ENTITY)
284 IPSNMPInfo *infoStruc = (IPSNMPInfo *) pResponseInfo;
285 int numInt, numRoutes;
287 /* This case is used to obtain general statistics about the
290 if (*pcbResponseInfoLen < sizeof(IPSNMPInfo) )
292 return (STATUS_BUFFER_TOO_SMALL);
297 memset(infoStruc, 0, sizeof(IPSNMPInfo));
299 /* Get the number of interfaces */
300 numInt = WSCNTL_GetEntryCount(WSCNTL_COUNT_INTERFACES);
303 ERR ("Unable to open /proc filesystem to determine number of network interfaces!\n");
306 /* Get the number of routes */
307 numRoutes = WSCNTL_GetEntryCount(WSCNTL_COUNT_ROUTES);
310 ERR ("Unable to open /proc filesystem to determine number of network routes!\n");
314 infoStruc->ipsi_numif = numInt; /* # of interfaces */
315 infoStruc->ipsi_numaddr = numInt; /* # of addresses */
316 infoStruc->ipsi_numroutes = numRoutes; /* # of routes */
318 /* FIXME: How should the below be properly calculated? ******************/
319 infoStruc->ipsi_forwarding = 0x0;
320 infoStruc->ipsi_defaultttl = 0x0;
321 infoStruc->ipsi_inreceives = 0x0;
322 infoStruc->ipsi_inhdrerrors = 0x0;
323 infoStruc->ipsi_inaddrerrors = 0x0;
324 infoStruc->ipsi_forwdatagrams = 0x0;
325 infoStruc->ipsi_inunknownprotos = 0x0;
326 infoStruc->ipsi_indiscards = 0x0;
327 infoStruc->ipsi_indelivers = 0x0;
328 infoStruc->ipsi_outrequests = 0x0;
329 infoStruc->ipsi_routingdiscards = 0x0;
330 infoStruc->ipsi_outdiscards = 0x0;
331 infoStruc->ipsi_outnoroutes = 0x0;
332 infoStruc->ipsi_reasmtimeout = 0x0;
333 infoStruc->ipsi_reasmreqds = 0x0;
334 infoStruc->ipsi_reasmoks = 0x0;
335 infoStruc->ipsi_reasmfails = 0x0;
336 infoStruc->ipsi_fragoks = 0x0;
337 infoStruc->ipsi_fragfails = 0x0;
338 infoStruc->ipsi_fragcreates = 0x0;
339 /************************************************************************/
341 /* Calculate size of out buffer */
342 *pcbResponseInfoLen = sizeof(IPSNMPInfo);
348 FIXME ("Unexpected Option for ENTITY_TYPE_ID request -> toi_class=0x%lx, toi_type=0x%lx\n",
349 pcommand->toi_class, pcommand->toi_type);
351 return (WSAEOPNOTSUPP);
358 /* IP_MIB_ADDRTABLE_ENTRY_ID is used to obtain more detailed information about a
359 particular network adapter */
360 case IP_MIB_ADDRTABLE_ENTRY_ID:
362 IPAddrEntry *baseIPInfo = (IPAddrEntry *) pResponseInfo;
363 char ifName[IFNAMSIZ+1];
367 if (*pcbResponseInfoLen < sizeof(IPAddrEntry))
369 return (STATUS_BUFFER_TOO_SMALL);
372 if (!WSCNTL_GetInterfaceName(pcommand->toi_entity.tei_instance, ifName))
374 ERR ("Unable to parse /proc filesystem!\n");
379 /* Get a socket so we can use ioctl */
380 if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
382 ERR ("Error creating socket!\n");
387 memset(baseIPInfo, 0, sizeof(IPAddrEntry) );
390 baseIPInfo->iae_index = pcommand->toi_entity.tei_instance;
393 strcpy (ifInfo.ifr_name, ifName);
394 ifInfo.ifr_addr.sa_family = AF_INET;
395 if (ioctlsocket(sock, SIOCGIFADDR, (ULONG*)&ifInfo) < 0)
397 baseIPInfo->iae_addr = 0x0;
401 struct WS_sockaddr_in* ipTemp = (struct WS_sockaddr_in*)&ifInfo.ifr_addr;
402 baseIPInfo->iae_addr = ipTemp->sin_addr.S_un.S_addr;
405 /* Broadcast Address */
406 strcpy (ifInfo.ifr_name, ifName);
407 if (ioctlsocket(sock, SIOCGIFBRDADDR, (ULONG *)&ifInfo) < 0)
409 baseIPInfo->iae_bcastaddr = 0x0;
413 struct WS_sockaddr_in* ipTemp = (struct WS_sockaddr_in*)&ifInfo.ifr_broadaddr;
414 baseIPInfo->iae_bcastaddr = ipTemp->sin_addr.S_un.S_addr;
418 strcpy(ifInfo.ifr_name, ifName);
419 if (ioctlsocket(sock, SIOCGIFNETMASK, (ULONG *)&ifInfo) < 0)
421 baseIPInfo->iae_mask = 0x0;
425 /* Trying to avoid some compile problems across platforms.
426 (Linux, FreeBSD, Solaris...) */
429 baseIPInfo->iae_mask = 0;
430 ERR ("Unable to determine Netmask on your platform!\n");
432 struct WS_sockaddr_in* ipTemp = (struct WS_sockaddr_in*)&ifInfo.ifr_addr;
433 baseIPInfo->iae_mask = ipTemp->sin_addr.S_un.S_addr;
436 struct WS_sockaddr_in* ipTemp = (struct WS_sockaddr_in*)&ifInfo.ifr_netmask;
437 baseIPInfo->iae_mask = ipTemp->sin_addr.S_un.S_addr;
441 /* FIXME: How should the below be properly calculated? ******************/
442 baseIPInfo->iae_reasmsize = 0x0;
443 baseIPInfo->iae_context = 0x0;
444 baseIPInfo->iae_pad = 0x0;
445 /************************************************************************/
447 /* Calculate size of out buffer */
448 *pcbResponseInfoLen = sizeof(IPAddrEntry);
454 /* This call returns the routing table.
455 * No official documentation found, even the name of the command is unknown.
457 * http://www.cyberport.com/~tangent/programming/winsock/articles/wscontrol.html
458 * and testings done with winipcfg.exe, route.exe and ipconfig.exe.
459 * pcommand->toi_entity.tei_instance seems to be the interface number
460 * but route.exe outputs only the information for the last interface
461 * if only the routes for the pcommand->toi_entity.tei_instance
462 * interface are returned. */
463 case IP_MIB_ROUTETABLE_ENTRY_ID: /* FIXME: not real name. Value is 0x101 */
465 int numRoutes, foundRoutes;
466 wscntl_routeentry *routeTable, *routePtr; /* route table */
468 IPRouteEntry *winRouteTable = (IPRouteEntry *) pResponseInfo;
470 /* Get the number of routes */
471 numRoutes = WSCNTL_GetEntryCount(WSCNTL_COUNT_ROUTES);
474 ERR ("Unable to open /proc filesystem to determine number of network routes!\n");
478 if (*pcbResponseInfoLen < (sizeof(IPRouteEntry) * numRoutes))
480 return (STATUS_BUFFER_TOO_SMALL);
483 /* malloc space for the routeTable */
484 routeTable = (wscntl_routeentry *) malloc(sizeof(wscntl_routeentry) * numRoutes);
487 ERR ("couldn't malloc space for routeTable!\n");
490 /* get the route table */
491 foundRoutes = WSCNTL_GetRouteTable(numRoutes, routeTable);
494 ERR ("Unable to open /proc filesystem to parse the route entries!\n");
498 routePtr = routeTable;
500 /* first 0 out the output buffer */
501 memset(winRouteTable, 0, *pcbResponseInfoLen);
503 /* calculate the length of the data in the output buffer */
504 *pcbResponseInfoLen = sizeof(IPRouteEntry) * foundRoutes;
506 for ( ; foundRoutes > 0; foundRoutes--)
508 winRouteTable->ire_addr = routePtr->wre_dest;
509 winRouteTable->ire_index = routePtr->wre_intf;
510 winRouteTable->ire_metric = routePtr->wre_metric;
511 /* winRouteTable->ire_option4 =
512 winRouteTable->ire_option5 =
513 winRouteTable->ire_option6 = */
514 winRouteTable->ire_gw = routePtr->wre_gw;
515 /* winRouteTable->ire_option8 =
516 winRouteTable->ire_option9 =
517 winRouteTable->ire_option10 = */
518 winRouteTable->ire_mask = routePtr->wre_mask;
519 /* winRouteTable->ire_option12 = */
532 FIXME ("Command ID Not Supported -> toi_id=0x%lx, toi_entity={tei_entity=0x%lx, tei_instance=0x%lx}, toi_class=0x%lx, toi_type=0x%lx\n",
533 pcommand->toi_id, pcommand->toi_entity.tei_entity, pcommand->toi_entity.tei_instance,
534 pcommand->toi_class, pcommand->toi_type);
536 return (WSAEOPNOTSUPP);
543 case WSCNTL_TCPIP_ICMP_ECHO:
545 unsigned int addr = *(unsigned int*)pRequestInfo;
547 int timeout= *(unsigned int*)(inbuf+4);
548 short x1 = *(unsigned short*)(inbuf+8);
549 short sendbufsize = *(unsigned short*)(inbuf+10);
550 char x2 = *(unsigned char*)(inbuf+12);
551 char ttl = *(unsigned char*)(inbuf+13);
552 char service = *(unsigned char*)(inbuf+14);
553 char type= *(unsigned char*)(inbuf+15); /* 0x2: don't fragment*/
556 FIXME("(ICMP_ECHO) to 0x%08x stub \n", addr);
562 FIXME("Protocoll Not Supported -> protocoll=0x%lx, action=0x%lx, Request=%p, RequestLen=%p, Response=%p, ResponseLen=%p\n",
563 protocoll, action, pRequestInfo, pcbRequestInfoLen, pResponseInfo, pcbResponseInfoLen);
565 return (WSAEOPNOTSUPP);
570 return (WSCTL_SUCCESS);
576 Helper function for WsControl - Get count of the number of interfaces
577 or routes by parsing /proc filesystem.
579 int WSCNTL_GetEntryCount(const int entrytype)
583 char buf[512]; /* Size optimized for a typical workstation */
591 case WSCNTL_COUNT_INTERFACES:
593 filename = PROCFS_NETDEV_FILE;
594 count = -2; /* two haeder lines */
598 case WSCNTL_COUNT_ROUTES:
600 filename = PROCFS_ROUTE_FILE;
601 count = -1; /* one haeder line */
611 /* open /proc filesystem file */
612 fd = open(filename, O_RDONLY);
617 /* read the file and count the EOL's */
618 while ((chrread = read(fd, buf, sizeof(buf))) != 0)
625 continue; /* read interupted by a signal, try to read again */
633 while ((ptr = memchr(ptr, '\n', chrread - (int) (ptr - buf))) > 0)
646 Helper function for WsControl - Get name of device from interface number
647 by parsing /proc filesystem.
649 int WSCNTL_GetInterfaceName(int intNumber, char *intName)
652 char buf[512]; /* Size doesn't matter, something big */
655 /* Open /proc filesystem file for network devices */
656 procfs = fopen(PROCFS_NETDEV_FILE, "r");
659 /* If we can't open the file, return an error */
663 /* Omit first two lines, they are only headers */
664 fgets(buf, sizeof(buf), procfs);
665 fgets(buf, sizeof(buf), procfs);
667 for (i=0; i<intNumber; i++)
669 /* Skip the lines that don't interest us. */
670 fgets(buf, sizeof(buf), procfs);
672 fgets(buf, sizeof(buf), procfs); /* This is the line we want */
675 /* Parse out the line, grabbing only the name of the device
676 to the intName variable
678 The Line comes in like this: (we only care about the device name)
679 lo: 21970 377 0 0 0 0 0 0 21970 377 0 0 0 0 0 0
682 while (isspace(buf[i])) /* Skip initial space(s) */
694 if (buf[i] == ':') /* FIXME: Not sure if this block (alias detection) works properly */
696 /* This interface could be an alias... */
698 char *dotname = intName;
699 *intName++ = buf[i++];
701 while (isdigit(buf[i]))
703 *intName++ = buf[i++];
708 /* ... It wasn't, so back up */
723 *intName++ = buf[i++];
733 Helper function for WsControl - This function returns the bytes (octets) transmitted
734 and received for the supplied interface number from the /proc fs.
736 int WSCNTL_GetTransRecvStat(int intNumber, unsigned long *transBytes, unsigned long *recvBytes)
739 char buf[512], result[512]; /* Size doesn't matter, something big */
740 int i, bufPos, resultPos;
742 /* Open /proc filesystem file for network devices */
743 procfs = fopen(PROCFS_NETDEV_FILE, "r");
746 /* If we can't open the file, return an error */
750 /* Omit first two lines, they are only headers */
751 fgets(buf, sizeof(buf), procfs);
752 fgets(buf, sizeof(buf), procfs);
754 for (i=0; i<intNumber; i++)
756 /* Skip the lines that don't interest us. */
757 fgets(buf, sizeof(buf), procfs);
759 fgets(buf, sizeof(buf), procfs); /* This is the line we want */
763 /* Parse out the line, grabbing the number of bytes transmitted
764 and received on the interface.
766 The Line comes in like this: (we care about columns 2 and 10)
767 lo: 21970 377 0 0 0 0 0 0 21970 377 0 0 0 0 0 0
770 /* Start at character 0 in the buffer */
773 /* Skip initial space(s) */
774 while (isspace(buf[bufPos]))
778 /* Skip the name and its trailing spaces (if any) */
781 if (isspace(buf[bufPos]))
784 if (buf[bufPos] == ':') /* Could be an alias */
788 while(isdigit (buf[bufPos]))
790 if (buf[bufPos] != ':')
792 if (buf[bufPos] == '\0')
804 while (isspace(buf[bufPos]))
808 /* This column (#2) is the number of bytes received. */
810 while (!isspace(buf[bufPos]))
812 result[resultPos] = buf[bufPos];
813 result[resultPos+1]='\0';
814 resultPos++; bufPos++;
816 *recvBytes = strtoul (result, NULL, 10); /* convert string to unsigned long, using base 10 */
819 /* Skip columns #3 to #9 (Don't need them) */
822 while (isspace(buf[bufPos]))
824 while (!isspace(buf[bufPos]))
829 /* This column (#10) is the number of bytes transmitted */
830 while (isspace(buf[bufPos]))
834 while (!isspace(buf[bufPos]))
836 result[resultPos] = buf[bufPos];
837 result[resultPos+1]='\0';
838 resultPos++; bufPos++;
840 *transBytes = strtoul (result, NULL, 10); /* convert string to unsigned long, using base 10 */
848 /* Parse the procfs route file and put the datas into routeTable.
849 * Return value is the number of found routes */
850 int WSCNTL_GetRouteTable(int numRoutes, wscntl_routeentry *routeTable)
852 int nrIntf; /* total number of interfaces */
853 char buf[256]; /* temporary buffer */
854 char *ptr; /* pointer to temporary buffer */
855 FILE *file; /* file handle for procfs route file */
856 int foundRoutes = 0; /* number of found routes */
857 typedef struct interface_t {
858 char intfName[IFNAMSIZ+1]; /* the name of the interface */
859 int intfNameLen; /* length of interface name */
861 interface_t *interface;
862 int intfNr; /* the interface number */
864 wscntl_routeentry *routePtr = routeTable;
866 /* get the number of interfaces */
867 nrIntf = WSCNTL_GetEntryCount(WSCNTL_COUNT_INTERFACES);
870 ERR ("Unable to open /proc filesystem to determine number of network interfaces!\n");
874 /* malloc space for the interface struct array */
875 interface = (interface_t *) malloc(sizeof(interface_t) * nrIntf);
878 ERR ("couldn't malloc space for interface!\n");
881 for (intfNr = 0; intfNr < nrIntf; intfNr++) {
882 if (WSCNTL_GetInterfaceName(intfNr, interface[intfNr].intfName) < 0)
884 ERR ("Unable to open /proc filesystem to determine the name of network interfaces!\n");
888 interface[intfNr].intfNameLen = strlen(interface[intfNr].intfName);
891 /* Open /proc filesystem file for routes */
892 file = fopen(PROCFS_ROUTE_FILE, "r");
895 /* If we can't open the file, return an error */
900 /* skip the header line */
901 fgets(buf, sizeof(buf), file);
903 /* parse the rest of the file and put the matching entries into routeTable.
904 Format of procfs route entry:
905 Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
906 lo 0000007F 00000000 0001 0 0 0 000000FF 0 0 0
908 while (fgets(buf, sizeof(buf), file)) {
910 /* find the interface of the route */
911 while ((strncmp(buf, interface[intfNr].intfName, interface[intfNr].intfNameLen) != 0)
912 && (intfNr < nrIntf))
916 if (intfNr < nrIntf) {
918 if (foundRoutes > numRoutes) {
919 /* output buffer is to small */
920 ERR("buffer to small to fit all routes found into it!\n");
926 ptr += interface[intfNr].intfNameLen;
927 routePtr->wre_intf = intfNr;
928 routePtr->wre_dest = strtoul(ptr, &ptr, 16); /* destination */
929 routePtr->wre_gw = strtoul(ptr, &ptr, 16); /* gateway */
930 strtoul(ptr, &ptr, 16); /* Flags; unused */
931 strtoul(ptr, &ptr, 16); /* RefCnt; unused */
932 strtoul(ptr, &ptr, 16); /* Use; unused */
933 routePtr->wre_metric = strtoul(ptr, &ptr, 16); /* metric */
934 routePtr->wre_mask = strtoul(ptr, &ptr, 16); /* mask */
935 /* strtoul(ptr, &ptr, 16); MTU; unused */
936 /* strtoul(ptr, &ptr, 16); Window; unused */
937 /* strtoul(ptr, &ptr, 16); IRTT; unused */
943 /* this should never happen */
944 WARN("Skipping route with unknown interface\n");
954 /***********************************************************************
955 * WSARecvEx (WSOCK32.1107)
957 * WSARecvEx is a Microsoft specific extension to winsock that is identical to recv
958 * except that has an in/out argument call flags that has the value MSG_PARTIAL ored
959 * into the flags parameter when a partial packet is read. This only applies to
960 * sockets using the datagram protocol. This method does not seem to be implemented
961 * correctly by microsoft as the winsock implementation does not set the MSG_PARTIAL
962 * flag when a fragmented packet arrives.
964 INT WINAPI WSARecvEx(SOCKET s, char *buf, INT len, INT *flags)
966 FIXME("(WSARecvEx) partial packet return value not set \n");
967 return recv(s, buf, len, *flags);
971 /***********************************************************************
972 * s_perror (WSOCK32.1108)
974 void WINAPI s_perror(LPCSTR message)
976 FIXME("(%s): stub\n",message);