network programming csc- 341

14
NETWORK PROGRAMMING CSC- 341 Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Upload: lobo

Post on 12-Jan-2016

35 views

Category:

Documents


0 download

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

Page 1: Network Programming CSC- 341

NETWORK PROGRAMMING

CSC- 341

Instructor:

Junaid Tariq,

Lecturer,

Department of Computer Science

Page 2: Network Programming CSC- 341

Lecture

1122

Page 3: Network Programming CSC- 341

PART 2

SOCKETS INTRODUCTIONCHAPTER 3

Page 4: Network Programming CSC- 341

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

Page 5: Network Programming CSC- 341

BZERO

Page 6: Network Programming CSC- 341

BCOPY

Page 7: Network Programming CSC- 341

BCMP

Page 8: Network Programming CSC- 341

#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.

Page 9: Network Programming CSC- 341

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

Page 10: Network Programming CSC- 341

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

Page 11: Network Programming CSC- 341

ATON & NTOA

Page 12: Network Programming CSC- 341

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

Page 13: Network Programming CSC- 341

PTON & NTOP

Page 14: Network Programming CSC- 341