How to use sys/socket.h functions in windows OS.

R

Ravikumar

Hi All,

The following code snippet is a part of s/w which is downloaded from
net. While compiling this code I got the following error.

...\..\snmplib\snmpTCPDomain.c(6) : fatal error C1083: Cannot open
include file: 'sys/socket.h': No such file or directory
NMAKE : fatal error U1077: 'cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3\VC98\BIN\NMAKE.EXE' :
return code '0x2'
Stop.

I just looked into the code and I found out that the problem is raised
because of sys/socket.h file. So please help me as how to use the
sys/socket.h file in windows OS . I am working on Windows OS. Hence I
am facing the problem. Is there any library I missed out.

Please help me as How to resolev this issue . Your thoughts will be
highly appreciated.

Thanks in Advance.

Thanks
Ravikumar

static int
netsnmp_tcp_accept(netsnmp_transport *t)
{
struct sockaddr *farend = NULL;
int newsock = -1, sockflags = 0;
socklen_t farendlen = sizeof(struct sockaddr_in);
char *str = NULL;

farend = (struct sockaddr *) malloc(sizeof(struct sockaddr_in));

if (t != NULL && t->sock >= 0) {
newsock = accept(t->sock, farend, &farendlen);

if (newsock < 0) {
DEBUGMSGTL(("netsnmp_tcp", "accept failed rc %d errno %d
\"%s\"\n",
newsock, errno, strerror(errno)));
free(farend);
return newsock;
}

if (t->data != NULL) {
free(t->data);
}

t->data = farend;
t->data_length = farendlen;
str = netsnmp_tcp_fmtaddr(NULL, farend, farendlen);
DEBUGMSGTL(("netsnmp_tcp", "accept succeeded (from %s)\n",
str));
free(str);

/*
* Try to make the new socket blocking.
*/

#ifdef WIN32
ioctlsocket(newsock, FIONBIO, &sockflags);
#else
if ((sockflags = fcntl(newsock, F_GETFL, 0)) >= 0) {
fcntl(newsock, F_SETFL, (sockflags & ~O_NONBLOCK));
} else {
DEBUGMSGTL(("netsnmp_tcp", "couldn't f_getfl of fd
%d\n",newsock));
}
#endif

return newsock;
} else {
free(farend);
return -1;
}
 
J

jacob navia

Windows sockets programming is slightly different to UNIX socket
programming.

There are differences in the header files, as you have noticed,
but there are also differences in the startup, library usage, and
many other things. If you do not read the docs before you
start compiling you will never arrive anywhere.

You will find more information under:
http://en.wikipedia.org/wiki/Winsock
http://www.noviway.com/Code/Winsock.aspx
http://www.faqs.org/faqs/windows/winsock-faq
http://tangentsoft.net/wskfaq/
 
C

Christopher Benson-Manica

Ravikumar said:
The following code snippet is a part of s/w which is downloaded from
net. While compiling this code I got the following error.
..\..\snmplib\snmpTCPDomain.c(6) : fatal error C1083: Cannot open
include file: 'sys/socket.h': No such file or directory
I just looked into the code and I found out that the problem is raised
because of sys/socket.h file. So please help me as how to use the
sys/socket.h file in windows OS . I am working on Windows OS. Hence I
am facing the problem. Is there any library I missed out.

(Probably. Ask on a group or forum where your system is topical.)

Your post is off-topic for comp.lang.c. Please visit

http://www.ungerhu.com/jxh/clc.welcome.txt
http://c-faq.com
http://benpfaff.org/writings/clc/off-topic.html

for posting guidelines and frequently asked questions. Thank you.
 
K

Kenneth Brody

Ravikumar said:
Hi All,

The following code snippet is a part of s/w which is downloaded from
net. While compiling this code I got the following error.

..\..\snmplib\snmpTCPDomain.c(6) : fatal error C1083: Cannot open
include file: 'sys/socket.h': No such file or directory
[...]

Socket programming (which is OT for clc anyway) is different for
Windows than it is for *nix systems. For Windows, you will need
to read up on "winsock" routines. Many things match up in winsock
to "normal" sockets, but there are many differences as well.

You'll need to ask one of the Windows programming groups for more
specifics. I'm not sure which one would be appropriate.

Here is a (very-OT) sample of the start of a module which accesses
sockets on both Windows and *nix. Take it to an appropriate winsock
group for any questions you may have.

==========
#if DOS_NT

#include <winsock.h>
#define SocketErrno (WSAGetLastError())
#define bcopy(src,dest,len) memmove(dest,src,len)

#else

#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/select.h>

#define SocketErrno errno

#define SOCKET int
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1

#endif
==========

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
C

CBFalconer

Ravikumar said:
The following code snippet is a part of s/w which is downloaded
from net. While compiling this code I got the following error.

..\..\snmplib\snmpTCPDomain.c(6) : fatal error C1083: Cannot open
include file: 'sys/socket.h': No such file or directory
NMAKE : fatal error U1077: 'cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3\VC98\BIN\NMAKE.EXE' :
return code '0x2'
Stop.

This newsgroup deals with the portable standard C language. That
does not define anything to do with sockets, nor does it contain a
"sys/socket.h" header. You should try a newsgroup that deals with
your peculiar system, probably something to do with windows.

Any advice you get here about sockets (or other off-topic material)
is automatically suspect, because the experts are using other
newsgroups, and faulty advice will probably not be caught. Those
giving such off-topic advice here are most likely to not understand
the purpose of newsgroups, and are thus even less likely to be
correct.

Read the following references before posting here again:

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net> (C-info)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top