Questions tagged [berkeley-sockets]

The Berkeley sockets API comprises a library for developing applications in the C programming language that perform inter-process communication, most commonly for communications across a computer network.

In computer networking, a socket is an endpoint of a bidirectional inter-process communication flow across an Internet Protocol-based computer network, such as the Internet.

A socket address is the combination of an IP address (the location of the computer) and a port (which is mapped to the application program process) into a single identity, much like one end of a telephone connection is the combination of a phone number and a particular extension.

The term is believed to have originated with the Berkeley Sockets API for Unix ca. 1983.

67 questions
3
votes
3 answers

Very Simple C++ TCP Echo Server

I am new to C++ network programming but have experience with Java sockets etc. I have been trying to write a simple TCP echo server in C++ but cannot really make any progress. I've tried looking at some code like at…
tree-hacker
  • 5,351
  • 9
  • 38
  • 39
3
votes
1 answer

Multiplexing with Berkeley Sockets

I have a web HTTP/1.1 server implementation that I've written in C++ using Berkeley sockets. I'm looking at implementing support for HTTP/2.0 (or SPDY) which allows for request and response multiplexing: The binary framing layer in HTTP/2.0 enables…
user152949
3
votes
3 answers

What might cause getaddrinfo() to return an error code of "1"?

More or less what it says in the title. I have a call to getaddrinfo like so: struct addrinfo crossplat, *actual_addr; crossplat.ai_family = AF_UNSPEC; //IPv4 or IPv6. crossplat.ai_socktype = SOCK_STREAM; if(int i = getaddrinfo("localhost",…
John Doucette
  • 4,370
  • 5
  • 37
  • 61
2
votes
1 answer

Purpose of SHUT_RDWR in shutdown() function in socket programming

When we call the shutdown() function on a socket with argument SHUT_RDWR, we stop read/write possibility on the socket, but the socket is still not destroyed. I can't understand the purpose of SHUT_RDWR. What does it give to us, and why do we need a…
John
  • 63
  • 6
2
votes
0 answers

C++: Attempting to "write" or "send" from server-side socket returns -1 after several hundred requests

I have written the code for a basic server in C++ using the sys/socket.h header. The method which runs the server and responds to requests is shown below. Code runs in a continuous loop so long as a member variable (Server::keep_server_ is set to…
2
votes
1 answer

Which protocol values are compatible with which combinations of domain and type in socket()?

I was playing around with Berkeley sockets, and then I did this: #include #include #include int main() { auto res = socket(AF_INET6, SOCK_STREAM, 58); if (res < 0) { std::cout << " Error in…
tkhurana96
  • 919
  • 7
  • 25
2
votes
0 answers

How does the SO_RCVBUF size correlate to incoming packet size?

Does setting the socket receive buffer to a specified number of bytes, directly correlate to how many sized messages can be stored? Example: If a 100 byte message is being continuously sent over UDP to a socket buffer set at 4,000 bytes, can I…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
2
votes
1 answer

epoll ET, what events should I subscribe to on listening socket?

I have a fd: socket(AF_INET6, SOCK_STREAM, ...) bind(fd, ...) listen(fd, ...) And I have a epoll instance. I need to know, what events should I subscribe to via epoll_ctl? I need Edge Triggered mode. I have those flags atm: EPOLLET | EPOLLIN Should…
marsgpl
  • 552
  • 2
  • 12
2
votes
1 answer

How to disable the timeout setsockopt() has set?

In the program I am developing, I've set a timeout using setsockopt() in order to prevent recvfrom() from blocking indefinitely. How can I disable the timeout? (I'm on Ubuntu)
Rapidturtle
  • 217
  • 1
  • 3
  • 13
2
votes
2 answers

Why does a PF_PACKET RAW socket stop missing packets after "Wireshark" was launched?

I need to receive incoming UDP packets using RAW socket, which is being opened using this code snippet: static int fd; char *iface; iface = "eth0"; if ( (fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0 ) { perror("socket"); } if…
2
votes
1 answer

Transmitting variable structure size with Berkeley socket over a TCP connection

I have the following structure defined in C, and I want to send it using Berkeley Socket over a TCP connection between client and a server in Linux: struct Argument{ int pid; int length; chat op; char *data; }; Since I have "char *data" which is a…
IoT
  • 607
  • 1
  • 11
  • 23
2
votes
1 answer

ioctl with FIONREAD return value

This question is related to What does FIONREAD of udp socket return? I tried to use next code on Mac: if( ioctl(socketId, FIONREAD, &totalPending) == -1 ) { printf("%d", totalPending); } numBytesRecv = recvfrom(socketId, buffer, maxLen, 0,…
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
2
votes
2 answers

How to notify an abnormal client termination to server?

As the Title already says im looking for a way, to get notified when a client closes his Session unnormal. I'm using the freeBSD OS. The server is running with Xamount threads (depending on CPUcore amount). So I'm not forking, and there isn't a own…
dhein
  • 6,431
  • 4
  • 42
  • 74
2
votes
2 answers

Canonical name or IP address - socket, linux and C

How can I know if a string is the canonical name or the IP address? Because if argv[1] is the IP address I do: sscanf(argv[2],"%" SCNu16,&server_port); inet_aton(argv[1],&server_address); remote_address.sin_family = AF_INET; remote_address.sin_port…
user2467899
  • 583
  • 2
  • 6
  • 19
2
votes
1 answer

binding with wifi interface in linux

I am working on a linux based system that has both LAN and WIFI interfaces. But I have to bind my socket with wifi interface only. Is there any general way to find out which interface is wifi, so I can bin my socket with it? If not, is there anyway…
ata
  • 8,853
  • 8
  • 42
  • 68