htonl, htons, ntohl, ntohs - convert values between host and network byte order
netlong = htonl(hostlong);
u_long netlong, hostlong;
netshort = htons(hostshort);
u_short netshort, hostshort;
hostlong = ntohl(netlong);
u_long hostlong, netlong;
hostshort = ntohs(netshort);
u_short hostshort, netshort;
These routines convert 16-bit and 32-bit quantities between network byte order and host byte order. On some non-ULTRIX machines these rou-
tines are defined as null macros in the include file <netinet/in.h>.
These routines are most often used with Internet addresses and ports as returned by and
Digital's systems handle bytes in the reverse of most UNIX-based systems.
See Alsogethostent(3n), getservent(3n)byteorder(3n)
Check Out this Related Man Page
byteorder(3SOCKET) Sockets Library Functions byteorder(3SOCKET)NAME
byteorder, htonl, htons, ntohl, ntohs - convert values between host and network byte order
cc [ flag... ] file... -lsocket -lnsl [ library... ]
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
These routines convert 16-bit and 32-bit quantities between network byte order and host byte order. On some architectures these routines
are defined as NULL macros in the include file <netinet/in.h>. On other architectures, the routines are functional when the host byte order
is different from network byte order.
The routines are most often used in conjunction with Internet addresses and ports as returned by gethostent() and getservent(). See geth-
ostbyname(3NSL) and getservbyname(3SOCKET).
See attributes(5) for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|MT-Level |Safe |
SEE ALSO gethostbyname(3NSL), getservbyname(3SOCKET), inet.h(3HEAD), attributes(5)SunOS 5.10 19 Feb 2004 byteorder(3SOCKET)
I having an issue while compiling a C program in USS (z/OS) machine.
I was able to create objest files (.o) from source (.c) files but when I try to create a binary file from the object files I am getting the below error.
$ cc util.o sock.o app.o -lnsl -o ptf
FSUM3067 The archive... (7 Replies)
I have created a UDP multicast transmitter and receiver, first using windows. But now I need the receiver to run on Ubuntu 10.04.
The code is the following:
/************************** Receiver *************************/
// Module Name: Receiver.c
// ... (0 Replies)
Ok so this is what I have.
I have separate client and server codes. I initially had the server listening and accepting connections from ONE port, and it was working great.
Now, what I want to do is, enable the server to listen and accept connections on TWO OR MORE ports , thus, effectively... (2 Replies)
my issue is - I have people connecting to my hosts from the outside world (for POC testing). There application listens on a port 3010 which is bound to the localhost. Using netstat -an | grep LISTEN it is the only port that is bound - ie: ftp, ssh etc listen on all interfaces. I need... (1 Reply)
Hi all, is it possible to use a different port number for daytime service. By default the port number of daytime service is 13, so what if I want to get the time from a different port number e.g say 9000 (or any other port).
I guess this would remain the same on the server side !... (2 Replies)
I have a simple client/server program I am using for learning purposes.
I have it setup so that after server is setup and listening it than goes into a loop where it accepts incoming client connections. After each connection, the client socket is than passed to a thread routine where it can be... (3 Replies)
I am getting error in bind function of "Address already in use" even also i have used the setsockopt function in that case .
int ret = 0;
int listenSock = 0;
struct sockaddr_in myAddr;
struct sockaddr_in ... (1 Reply)
I have posted several times regarding my application.
In a nutshell, I have a server application that logs attached instrument data over USB and Ethernet. My restriction here is having two wires or more to plug all instrumentation in - at least one for USB and at least one for ethernet.
... (16 Replies)
Sorry for the “word salad” subject, but I wanted to cast a wide net for help.
I've created an IP (Internet Protocol) server which serves HTTP, SMTP, and FTP requests.
As you probably know, they all require creating a socket, listening on it, accepting connections, and then having a short... (3 Replies)
Hi all, I'm new programming in C, so I had the next message in my code:
Dual.c:88:20: warning: pointer type mismatch in conditional expression : &clientSa.sin6.sin6.sin6_addr,
Any help would be great
#include... (1 Reply)
I'm trying to make a "dual/server client" (ipv4,ipv6) with sockets in linux but i don't know how to join both codes. I have a dual client ipv4 and ipv6, but i have problems with the server if you notice the only difference between them it's the AF_INET (pf_inet ipv4, and if_inet6 ipv6) and the port... (3 Replies)
I am setting the socket option SO_BINDTODEVICE for eth0 to be able to route the packets only through that interface. However, bind() fails with "Port already in use" error with this option when the server is restarted despite having the socket option SO_REUSEADDR.
Here is my code snippet:
... (0 Replies)