Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sockets(examples): remove unused register keyword, replace bzero with memset #410

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ We now know enough to write a very simple client, one that will get current time
#include <unistd.h>

int main() {
register int s;
register int bytes;
int s, bytes;
struct sockaddr_in sa;
char buffer[BUFSIZ+1];

Expand All @@ -572,7 +571,7 @@ int main() {
return 1;
}

bzero(&sa, sizeof sa);
memset(&sa, '\0', sizeof(sa));

sa.sin_family = AF_INET;
sa.sin_port = htons(13);
Expand Down Expand Up @@ -718,8 +717,8 @@ The child calls `listen`, then starts an endless loop, which accepts a connectio
#define BACKLOG 4

int main() {
register int s, c;
int b;
int s, c;
socklen_t b;
struct sockaddr_in sa;
time_t t;
struct tm *tm;
Expand All @@ -730,7 +729,7 @@ int main() {
return 1;
}

bzero(&sa, sizeof sa);
memset(&sa, '\0', sizeof(sa));

sa.sin_family = AF_INET;
sa.sin_port = htons(13);
Expand All @@ -747,11 +746,9 @@ int main() {
case -1:
perror("fork");
return 3;
break;
default:
close(s);
return 0;
break;
case 0:
break;
}
Expand All @@ -773,7 +770,6 @@ int main() {

if ((t = time(NULL)) < 0) {
perror("daytimed time");

return 6;
}

Expand Down Expand Up @@ -976,14 +972,14 @@ This allows us to create a much more flexible-and much more useful-version of ou
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int main(int argc, char *argv[]) {
register int s;
register int bytes;
int s, bytes;
struct sockaddr_in sa;
struct hostent *he;
char buf[BUFSIZ+1];
Expand All @@ -994,19 +990,19 @@ int main(int argc, char *argv[]) {
return 1;
}

bzero(&sa, sizeof sa);
memset(&sa, '\0', sizeof(sa));

sa.sin_family = AF_INET;
sa.sin_port = htons(13);

host = (argc > 1) ? (char *)argv[1] : "time.nist.gov";
host = (argc > 1) ? argv[1] : "time.nist.gov";

if ((he = gethostbyname(host)) == NULL) {
herror(host);
return 2;
}

bcopy(he->h_addr_list[0],&sa.sin_addr, he->h_length);
memcpy(&sa.sin_addr, he->h_addr_list[0], he->h_length);

if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) {
perror("connect");
Expand Down
Loading