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
12
votes
2 answers

Socket Shutdown: when should I use SocketShutdown.Both

I believe the shutdown sequence is as follows (as described here): The MSDN documentation (remarks section) reads: When using a connection-oriented Socket, always call the Shutdown method before closing the Socket. This ensures that all data is…
Pooven
  • 1,744
  • 1
  • 25
  • 44
12
votes
5 answers

How to ignore your own broadcast udp packets

For the following I'm assuming one network card. I have a component of my program which is designed to let others in the subnet know of its existence. For this, I've implemented a solution where whenever the program starts up (and periodically…
laura
  • 7,280
  • 4
  • 35
  • 43
11
votes
4 answers

Dereferencing pointer does break strict anti-aliasing rules using Berkeley sockets

I've got code that looks something like this, where addr is a sockaddr*: struct sockaddr_in *sin = (struct sockaddr_in *) addr; const char *IP=inet_ntoa(sin -> sin_addr); I believe this is very typical code for using Berkeley sockets. However, when…
Nantucket
  • 1,647
  • 3
  • 14
  • 25
10
votes
4 answers

About recv and the read buffer - C Berkeley Sockets

I am using berkeley sockets and TCP (SOCK_STREAM sockets). The process is: I connect to a remote address. I send a message to it. I receive a message from it. Imagine I am using the following buffer: char recv_buffer[3000]; recv(socket,…
NeDark
  • 1,212
  • 7
  • 23
  • 36
8
votes
2 answers

What happens if one doesn't call [POSIX's] `recv` "fast enough"?

I want to account for a possible scenario where clients of my TCP/IP stream socket service send data to my service faster than it manages to move the data to its buffers (I am talking about application buffers, naturally) with recv and work with…
Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
8
votes
2 answers

Binding Sockets to IPv6 Addresses

I am trying to write a web server that listens on both IPv4 and IPv6 addresses. However, the code that I originally wrote did not work. Then I found out that the IPv6 structures work for both IPv4 and IPv6. So now I use the IPv6 structures…
tpar44
  • 1,431
  • 4
  • 22
  • 35
7
votes
1 answer

IPv6 scope ID vs IPv4

Recently I was working with the Berkeley socket API for IPv6, and noticed that IPv6 addresses (sockaddr_in6) have a field called sin6_scope_id, which was not part of IPv4 addresses. After searching around a bit, I’ve learned that scope_id is meant…
Tamás Zahola
  • 9,271
  • 4
  • 34
  • 46
6
votes
3 answers

Can someone give me a good explanation of 'send' behavior for non-blocking sockets?

I have read the documentation at least 10 times now and have also read some 10 or so code snippets and full programs where non-blocking sockets are used for sending data. The problem is that some of the tutorials are either for beginners (Beejs…
Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
6
votes
2 answers

Problems with IPv6 connect in C

I'm trying to code an agnostic echo server, that could accept both IPv4 and IPv6 connection. I'm working with addrinfo structure, set with getaddrinfo. Ipv4 connect has no problem while I can't get a working ipV6 connection. I think my problem could…
Mala88
  • 63
  • 1
  • 5
5
votes
5 answers

How to Avoid DOS Attack using Berkeley Sockets in C++

I'm working my way through UNIX Network Programming Volume 1 by Richard Stevens and attempting to write a TCP Echo Client that uses the Telnet protocol. I'm still in the early stages and attempting to write the read and write functions. I'd like…
Daniel Bingham
  • 12,414
  • 18
  • 67
  • 93
4
votes
2 answers

Get remote address/IP - C Berkeley Sockets

If I have a socket file descriptor connected (either by connect or by bind), type SOCK_STREAM, is it possible to get the remote address / IP address? I need to do this within a function where I don't have any other data than the socket file…
NeDark
  • 1,212
  • 7
  • 23
  • 36
3
votes
1 answer

Get gateway address in C/C++

I use ioctl() to set the gateway address (SIOCADDRT with RTF_GATEWAY in the flags). What's the standard ioctl routine to retrieve it?
user788041
  • 81
  • 3
  • 8
3
votes
1 answer

Determining the Destination Timestamp of an (S)NTP packet?

I'm trying to create a simple SNTP client in C using the Berkeley sockets API, but I'm having trouble calculating the adjusted time from the response message. I got this from RFC2030. When the server reply is received, the client determines a…
Pieter
  • 31,619
  • 76
  • 167
  • 242
3
votes
2 answers

User buffer size to receive multicast packets?

The below code is from Git. It joins a multicast group and receives packets. Here we loop and receive the data in a buffer called msgbuf: while (1) { char msgbuf[MSGBUFSIZE]; const int addrlen = sizeof(addr); const int nbytes =…
user997112
  • 29,025
  • 43
  • 182
  • 361
3
votes
2 answers

Why do Berkeley sockets require byte swapping?

I understand that on the wire, most integers are in big endian format. But why is it the burden of the application to do the byte swapping in structures like sockaddr_in and not the kernels, where all the low level work actually happens? It would…
0x400921FB54442D18
  • 725
  • 1
  • 5
  • 18
1
2 3 4 5