Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Programming CSC- 341

Similar presentations


Presentation on theme: "Network Programming CSC- 341"— Presentation transcript:

1 Network Programming CSC- 341
Instructor: Junaid Tariq, Lecturer, Department of Computer Science

2 12 Lecture Network Programming

3 Part 2 Sockets Introduction Chapter 3

4 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 */

5 BZERO

6 BCOPY

7 BCMP

8 Byte Manipulation Functions Cont.
#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 0 Each bytes is considered as unsigned char */

9 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

10 #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 */ 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*/

11 ATON & NTOA

12 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*/

13 PTON & NTOP

14


Download ppt "Network Programming CSC- 341"

Similar presentations


Ads by Google