network programming csc- 341

Post on 12-Jan-2016

28 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Network Programming CSC- 341. Instructor: Junaid Tariq, Lecturer, Department of Computer Science. 12. Lecture. Network Programming. Part 2 Sockets Introduction Chapter 3. Byte Manipulation Functions. #include void bzero ( void *dest , size_t nbytes ); - PowerPoint PPT Presentation

TRANSCRIPT

NETWORK PROGRAMMING

CSC- 341

Instructor:

Junaid Tariq,

Lecturer,

Department of Computer Science

Lecture

1122

PART 2

SOCKETS INTRODUCTIONCHAPTER 3

BYTE MANIPULATION FUNCTIONS

#include <strings.h>

void bzero(void *dest, size_t nbytes);

/* sets the specified no of bytes to zero */

void bcopy(const void *src, void *dest, size_t nbytes);

/* byte by byte copy from source to destination */

int bcmp(const void *ptr1, const void *ptr2, size_t nbytes);

/* return 0 if equal, nonzero if unequal */

BZERO

BCOPY

BCMP

#include <string.h>void *memset(void *dest, int c, size_t len);/* sets specified no of bytes to ‘c’ */

void *memcpy(void *dest, const void *src, size_t nbytes);/* byte string copy from source to destination but undefined if source and

destination buffers overlap*/

int memcmp(const void *ptr1, const void *ptr2, size_t nbytes);

/* ptr1 < ptr2 : less than 0 (for first unequal bytes) ptr1 > ptr2 : greater than 0 (for first unequal bytes) ptr1 = ptr2 : than 0Each bytes is considered as unsigned char */

BYTE MANIPULATION FUNCTIONS CONT.

3.6 INET_ATON,INET_ADDR, INET_NTOA FUNCTIONS

Convert internet address between ASCII string and network byte ordered binary values(as stored in socket address structure)

Used for IPv4 addresses conversion

For both IPv4 and IPv6 we have : inet_pton , inet_ntop

#include<arpa/inet.h>

For ASCII to network binary:int inet_aton(const char *strptr, struct in_addr

*addrptr); /* return : 1 if successful,0 on error */

For ASCII to network binary:in_addr_t inet_addr(const char *strptr); /* return : 32bit binary network byte ordered IPv4

address; INADDR_NONE (32 one-bits) if error */

For network binary to ASCII:char *inet_ntoa(struct in_addr inaddr);

/*return pointer to dotted-decimal string*/

ATON & NTOA

3.7 INET_PTON,INET_NTOP FUNCTION Both IPv4,IPv6 address conversion p : presentation(string) n : numeric(binary)

#include<arpa/inet.h> int inet_pton(int family, const char *strptr, void *addrptr); /* return: 1 if OK, 0 if input not a valid presentation format, -1 if family not

supported */

const char *inet_ntop(int family, const void *addrptr, char *strpt, size_t len);

/* return : pointer to result if OK, NULL if length allocated for string is smaller then required size, 16 for IPv4 dotted decimal and 46 for IPv6 hex*/

/* len : size of the destination string allocated by the caller*/

PTON & NTOP

top related