Skip to content
Snippets Groups Projects
Commit 92283785 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiel-Programme und Tafelbild 30.6.2017

parent 871be08b
No related branches found
No related tags found
No related merge requests found
30.06.2017
- Quelltexte RP6 und Linux-Scheduler
- Signale
- Netzwerk-Interfaces
Signale, 23.05.2016, 09:29:58
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Prozeßkontrolle von bash aus: ^C, ^Z, jobs, kill -INT %3, fg, bg
Prozeßkontrolle: ps, ps aux, pstree, kill
Signal-Handler schreiben: signals-*.c
Aufgabe: "Timer-Interrupt" programmieren
Netzwerk-Interfaces, 30.05.2016, 10:36:28
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Loopback-Treiber:
Datei: ~/bo/2016ss/bs/20160509/linux-source-3.16/drivers/net/loopback.c
Suchbegriff: struct net_device_ops
drivers/net: Netzwerkkarten.
net: Protokolle.
Datei: ~/bo/2016ss/bs/20160509/linux-source-3.16/net/
Suchbegriff: ether_setup
Netzwerk-Treiber: früher auch unter /dev, jetzt nicht mehr
- "keine klassischen Datei-Operationen" --> serielle Schnittstellen
- historisch: Hot-Plug-Fähigkeit --> udev [--> systemd]
Netzwerke in der Praxis:
Datei: ~/bo/2013ss/net/script/net-2013ss.pdf
SMTP-Sitzung: E-Mail versenden
$ nc 88.198.170.60 25
220 mx1.gerwinski.de ESMTP Exim 4.84_2 Mon, 30 May 2016 12:39:01 +0200
HELO microsoft.com
250 mx1.gerwinski.de Hello office.g-n-u.de [82.207.128.254]
MAIL FROM: <korbinian.moeller@hs-bochum.de>
250 OK
RCPT TO: <peter@gerwinski.de>
250 Accepted
DATA
354 Enter message, ending with "." on a line by itself
Subject: Test
From: Bill Gates <gates@microsoft.com>
To: Steve Jobs <jobs@apple.com>
Hi! B-)
.
250 OK id=1b7Kbi-0003Ut-CZ
QUIT
221 mx1.gerwinski.de closing connection
$
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define TARGET_HOST "localhost"
#define PORT 1234
#define MESSAGE "Hello, world!\n"
void error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
int main (void)
{
int s;
struct sockaddr_in name;
if ((s = socket (PF_INET, SOCK_STREAM, 0)) < 0)
error ("cannot create socket");
memset (&name, 0, sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons (PORT);
name.sin_addr.s_addr = htonl (INADDR_ANY);
struct hostent *ho = gethostbyname (TARGET_HOST);
if (!ho)
{
close (s);
error ("name server lookup error");
}
if (ho->h_length > (int) sizeof (name.sin_addr))
ho->h_length = sizeof (name.sin_addr);
memcpy (&name.sin_addr, ho->h_addr, ho->h_length);
if (connect (s, (struct sockaddr *) &name, sizeof (name)) < 0)
{
close (s);
error ("cannot connect to socket");
}
send (s, MESSAGE, strlen (MESSAGE), 0);
shutdown (s, SHUT_RDWR);
close (s);
return 0;
}
20170630/photo-20170630-150511.jpg

135 KiB

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define PORT 1234
#define MESSAGE "Hello, world!\n"
void error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
int main (void)
{
int s;
struct sockaddr_in name;
if ((s = socket (PF_INET, SOCK_STREAM, 0)) < 0)
error ("cannot create socket");
memset (&name, 0, sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons (PORT);
name.sin_addr.s_addr = htonl (INADDR_ANY);
int on = 1;
setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof (on));
if (bind (s, (struct sockaddr *) &name, sizeof (name)) < 0)
{
close (s);
error ("cannot bind socket");
}
if (listen (s, 16) < 0)
{
close (s);
error ("cannot listen on socket");
}
struct sockaddr_in clientname;
size_t size = sizeof (clientname);
s = accept (s, (struct sockaddr *) &clientname, &size);
if (s < 0)
error ("cannot accept connection");
char *host_address = inet_ntoa (clientname.sin_addr);
char *host_name;
struct hostent *hp = gethostbyaddr ((void *) &clientname.sin_addr, sizeof (clientname.sin_addr), clientname.sin_family);
if (hp)
host_name = hp->h_name;
else
host_name = inet_ntoa (clientname.sin_addr);
int remote_port = ntohs (clientname.sin_port);
printf ("connection from %s [%s], port %d\n",
host_name, host_address, remote_port);
send (s, MESSAGE, strlen (MESSAGE), 0);
shutdown (s, SHUT_RDWR);
close (s);
return 0;
}
#include <signal.h>
#include <stdio.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
signal (SIGINT, signal_handler);
while (1);
return 0;
}
#include <signal.h>
#include <stdio.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
if (signal (SIGINT, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
while (1);
return 0;
}
#include <signal.h>
#include <stdio.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
if (signal (SIGUSR1, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
while (1);
return 0;
}
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
if (signal (SIGVTALRM, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
struct itimerval timer;
timer.it_value.tv_sec = 1;
timer.it_value.tv_usec = 0;
timer.it_interval.tv_sec = 1;
timer.it_interval.tv_usec = 0;
setitimer (ITIMER_VIRTUAL, &timer, NULL);
while (1);
return 0;
}
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
if (signal (SIGVTALRM, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
struct itimerval timer;
timer.it_value.tv_sec = 1;
timer.it_value.tv_usec = 0;
timer.it_interval.tv_sec = 1;
timer.it_interval.tv_usec = 0;
setitimer (ITIMER_VIRTUAL, &timer, NULL);
while (1)
sleep (10);
return 0;
}
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
}
int main (void)
{
if (signal (SIGALRM, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
struct itimerval timer;
timer.it_value.tv_sec = 1;
timer.it_value.tv_usec = 0;
timer.it_interval.tv_sec = 1;
timer.it_interval.tv_usec = 0;
setitimer (ITIMER_REAL, &timer, NULL);
while (1)
sleep (10);
return 0;
}
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static void signal_handler (int signo)
{
printf ("Hello, world!\n");
alarm (1);
}
int main (void)
{
if (signal (SIGALRM, signal_handler) == SIG_ERR)
{
fputs ("Error installing signal handler.\n", stderr);
return 1;
}
alarm (1);
while (1)
sleep (10);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment