bsd-sockets

How do I create RAW TCP/IP packets in C++?

I'm a beginning C++ programmer / network admin, but I figure I can learn how to do this if someone points me in the right direction. Most of the tutorials are demonstrated using old code that no longer works for some reason. Since I'm on Linux, all I need is an explanation on how to write raw Berkeley sockets. Can someone give me a qui...

socket listen backlog parameter, how to determine this value?

How should I determine what to use for a listening socket's backlog parameter? Is it a problem to simply specify a very large number? ...

Lower than low level common bsd sockets

How do you do low low level sockets in C, example: actually sending a SYN. ...

Is it possible to unlisten on a socket ?

Is it possible to unlisten on a socket after you have called listen(fd, backlog)? Edit: My mistake for not making myself clear. I'd like to be able to temporarily unlisten on the socket. Calling close() will leave the socket in the M2LS state and prevent me from reopening it (or worse, some nefarious program could bind to that socket) ...

good resource for socket errors?

Where can I find a list of all types of bsd style socket errors? ...

PostgreSQL UNIX domain sockets vs TCP sockets

I wonder if the UNIX domain socket connections with postgresql are faster then tcp connections from localhost in high concurrency rate and if it does, by how much? ...

Is there any benefit to using windows winsock API functions compared to BSD-style socket functions?

Is there any benefit on Windows to use the WSA winsock functions compared to the BSD-style ones? ...

Problems receiving data over a TCP client socket in 'C'

I'm trying to make a TCP Client program in C where the client will start up, connect to a server. Then it will send a little information and then just listen to what it receives and react accordingly. The part that I'm having trouble with is the continuous listening. Here is what I have ... while (1) { numbytes = recv(sockfd, buf, ...

How to signal select() to return immediately?

I have a worker thread that is listening to a TCP socket for incoming traffic, and buffering the received data for the main thread to access (let's call this socket A). However, the worker thread also has to do some regular operations (say, once per second), even if there is no data coming in. Therefore, I use select() with a timeout, so...

Mixing File Handles and Sockets in Winsock

I'm porting some code from BSD sockets to Winsock, and I'm not sure how to handle the case below. My original application runs a select on both stdin and the network socket: FD_SET(sock, &fd); FD_SET(0, &fd); ... if (select(..., &fd, ... )...) Trying to run this in Winsock gives an error 10038 (WSAENOTSOCK), which makes sense, since ...

Weird HTTP problem/mistake with Lisp

I'm attempting to learn a little more about handling sockets and network connections in SBCL; so I wrote a simple wrapper for HTTP. Thus far, it merely makes a stream and performs a request to ultimately get the header data and page content of a website. Until now, it has worked at somewhat decently. Nothing to brag home about, but it a...

Can the server use the same socket to send the response to the client? how?

I am using Berkeley sockets (both: Internet domain and Unix domain) and I was wondering if the server can use the same sockets for reading the request and writing a response to the client. Or should the client create an other socket to wait for the replay and the server connect to it after processing the message received. By the way, I ...

Joining 2 Sockets?

Is it possible to join two sockets? For example, if a process is acting as a router of messages between 2 other processes at some point being able to step aside would save a bunch of socket IO. This seems like it should be possible, but I've never even HEARD of it being done! If it is possible, is it possible on Linux AND Windows? If ...

Comparing string data received from a socket in C

I have a question on sockets. I have this code: while(bytes = recv(sClient, cClientMessage, 599, 0)){ This puts the message it recives into cClientMessage and the message is always "Message". How I made an if statement like if(cClientMessage == "Message"){//do func}. Now this code will not do the function I want. I think this is b...

How to restart a sockets program?

I need my server to stay connected to the server. Does anyone know how to do this? Or post links tutorials anything? Also it says when it restarts 'could not accept client' so how would I clear everything and make it accept it? ...

When zeroing a struct such as sockaddr_in, sockaddr_in6 and addrinfo before use, which is correct: memset, an initializer or either?

Whenever I look at real code or example socket code in books, man pages and websites, I almost always see something like: struct sockaddr_in foo; memset(&foo, 0, sizeof foo); /* or bzero(), which POSIX marks as LEGACY, and is not in standard C */ foo.sin_port = htons(42); instead of: struct sockaddr_in foo = { 0 }; /* if at least o...

Problem with creating sockets using CFSocket in Objective-C (iPhone app)

Ok, I have a problem with building a socket using Objective-C. If you'll take a look at my code below, through help with example code and other sources, I was able to build a complete socket I believe. The problem is that when I compile it, it builds fine (no syntax problems), but there are no sockets being created. As you'll notice I've...

BSD Socket issue: inet_ntop returning "0.0.0.0"

I'm trying to get the IP of the machine a socket I've bound is listening on. The port number printed works fine, but the address is "0.0.0.0". Here's the relevant code. res has been passed to getaddrinfo and getsockname before getting to this code. char ip[INET_ADDRSTRLEN]; struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr; ...

How to set TCP_NODELAY on BSD socket on Solaris?

I am trying to turn off Nagle's algorithm for a BSD socket using: setsockopt(newSock, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof flag); but the compiler claims TCP_NODELAY hasn't been seen before: error: `TCP_NODELAY' undeclared (first use this function) This is the full list of includes for the file this is in: #include <arpa...

UNIX nonblocking I/O: O_NONBLOCK vs. FIONBIO

In every example and discussion I run across in the context of BSD socket programming, it seems that the recommended way to set a file descriptor to nonblocking I/O mode is using the flag to fcntl(), e.g. int flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); I've been doing network programming in UNIX for over te...