Add ucat
This commit is contained in:
parent
eeae3fb19d
commit
5e745434fc
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
kernel-hdr
|
||||
build
|
||||
progs/rsh
|
||||
progs/rc
|
||||
|
3
etc/inittab
Normal file
3
etc/inittab
Normal file
@ -0,0 +1,3 @@
|
||||
# Runlevels: 1
|
||||
|
||||
l0:1:once:/bin/login
|
38
progs/base/bin/ucat.c
Normal file
38
progs/base/bin/ucat.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
#include <ygg/un.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
struct sockaddr_un un;
|
||||
ssize_t rd;
|
||||
int fd;
|
||||
char buf[1024];
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s SOCKET\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
un.sun_family = AF_UNIX;
|
||||
strcpy(un.sun_path, argv[1]);
|
||||
|
||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
perror("socket()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(fd, (struct sockaddr *) &un, sizeof(un)) != 0) {
|
||||
perror("connect()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((rd = recv(fd, buf, sizeof(buf), 0)) > 0) {
|
||||
write(STDOUT_FILENO, buf, rd);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user