TOP
SSV Software Systems Register  Register
Log in to check your private messages  Log in to check your private messages
Startseite FAQ Search Mitglieder Profile  Log in 
SSV Support-Forum
Network time protocol

 
Post new topic   Reply to topic    SSV-Forum Forum Index >>> DNP/5280
<<< Previous topic - Next topic >>>  
Display posts from previous:   
Author Message
Stephan



Joined: 06 Apr 2010
Posts: 6
Location: München

PostPosted: 09.04.2010, 19:09    Post subject: Network time protocol Reply with quote

Hallo,

um die Uhr auf dem DNP/5280 zu stellen verwende ich das Binary ntpclient.

# /home/ntpclient -i 3 -s -h 192.53.103.108
40275 68702.779 77698.0 6.2 -3598474220.4 1266.5 0

Das liefert in der Sommerzeit die Uhrzeit immer um 2 Stunden zurück (Winterzeit eine Stunde zurück).

Um 20:05.08 Uhr (Sommerzeit):

# date
Fri Apr 9 18:05:08 UTC 2010

Liegt das an der Zeitzone? Wie kann ich auf MEZ umstellen?

Gibt es die Möglichkeit DNS auf dem System zu verwenden? Falls sich bei dem Server die IP Adresse ändert wird mein System kein Zeitupdate mehr machen.

Danke und Grüße,
Stephan
Back to top
View user's profile Send private message
mha



Joined: 05 May 2006
Posts: 28

PostPosted: 13.04.2010, 14:51    Post subject: Reply with quote

Hallo Stephan,

das SSV uClinux Image hat keine Unterstützung für DNS und Zeitzonen eingebaut.
Sie können aber mit den Quellen der uClinux Distribution eigene Features zum Image
hinzufügen.

Gruß MHA
Back to top
View user's profile Send private message
Stephan



Joined: 06 Apr 2010
Posts: 6
Location: München

PostPosted: 13.04.2010, 20:09    Post subject: Network time protocol Reply with quote

Hallo MHA,

ok. Dann werde ich ein Binary bauen, dass ein UDP Paket an einen DNS Server schickt um einen Domainnamen aufzulösen.

Danke und Grüße,
Stephan
Back to top
View user's profile Send private message
Stephan



Joined: 06 Apr 2010
Posts: 6
Location: München

PostPosted: 25.04.2010, 14:56    Post subject: Network time protocol Reply with quote

Das Programm könnte etwa so aussehen:

// *****************************************************************
// Domain Name Resolution
//
// Das Programm löst den Domain Namen ptbtime1.ptb.de in seine
// IP Adresse auf (RFC 1035/4). Es ist keine Sicherung implementiert
// (UDP Pakete können verloren gehen).
//
// *****************************************************************

// *****************************************************************
// Filename: dns.c
// Author: Stephan Hüls
// Date: 24.04.2010
// *****************************************************************

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>

void shortToByte(short value, char * byte1, char * byte2)
{
// Bei x86 Linux PC byte1 und byte2 vertauschen
if(byte2 != NULL)
{
*byte2 = (char) (value & 0xFF);
}
if(byte1 != NULL)
{
*byte1 = (char) ( (value >> 8 ) & 0xFF);
}
}

int main(void)
{
unsigned char packet[33];
int udb_socket;
struct sockaddr_in dns_server;
char byte1;
char byte2;
short headerSecondShort;
short qdcount;
short ancount;
short nscount;
short arcount;
short qtype, qclass;
int size_dns_server;
char answer[65536];
int bytes_received;
int ip[4];
//int count;


udb_socket = socket(AF_INET , SOCK_DGRAM , IPPROTO_UDP); // UDP Socket

dns_server.sin_family = AF_INET;
dns_server.sin_port = htons(53); // Port 53 (DNS)
dns_server.sin_addr.s_addr = inet_addr("212.18.3.5"); // DNS Server

// Header Anfrage

// Session ID (irgendwas)
packet[0] = 0xAA;
packet[1] = 0xAA;

// QR=0 (Query, kein Response)
// OPCODE=0000 (Standardquery)
// AA=0 (für Antwort)
// TC=0 (keine Verkürzung)
// RD=1 (falls Antwort nicht vorhanden rekursiv weitersuchen)
// RA=0 (für Antwort)
// Z=000 (reserviert für zukünftige Sachen)
// RCODE=0000 (für Antwort)
// 0 0000 0 0 1 0 000 0000 = 0x100
headerSecondShort = htons(0x100);
shortToByte(headerSecondShort, &byte1, &byte2);
packet[2] = byte1;
packet[3] = byte2;

qdcount = htons(1); // Eine Anfrage
shortToByte(qdcount, &byte1, &byte2);
packet[4] = byte1;
packet[5] = byte2;

ancount = htons(0); // Ressource Records in der Antwort
shortToByte(ancount, &byte1, &byte2);
packet[6] = byte1;
packet[7] = byte2;

nscount = htons(0); // Server Ressource Records im authority Record
shortToByte(nscount, &byte1, &byte2);
packet[8] = byte1;
packet[9] = byte2;

arcount = htons(0); // Ressource Record im erweiterten Record
shortToByte(arcount, &byte1, &byte2);
packet[10] = byte1;
packet[11] = byte2;

// Anfrage

// QNAME
packet[12] = 0x08; // ptbtime1.ptb.de = 8ptbtime13ptb2de
packet[13] = 'p';
packet[14] = 't';
packet[15] = 'b';
packet[16] = 't';
packet[17] = 'i';
packet[18] = 'm';
packet[19] = 'e';
packet[20] = '1';
packet[21] = 0x03;
packet[22] = 'p';
packet[23] = 't';
packet[24] = 'b';
packet[25] = 0x02;
packet[26] = 'd';
packet[27] = 'e';
packet[28] = 0x00; // Nullterminierung

// QTYPE
qtype = htons(1); // IPv4
shortToByte(qtype, &byte1, &byte2);
packet[29] = byte1;
packet[30] = byte2;

// QCLASS
qclass = htons(1); // Internet
shortToByte(qclass, &byte1, &byte2);
packet[31] = byte1;
packet[32] = byte2;

// Sende Anfrage

if(sendto(udb_socket, (char *) packet, sizeof(packet), 0, (struct sockaddr *) &dns_server, sizeof(dns_server)) == 0)
{
printf("Sendefehler!\n");
}

// Empfange Antwort

size_dns_server = sizeof(dns_server);

if((bytes_received = recvfrom(udb_socket, (char*) answer, sizeof(answer), 0, (struct sockaddr*) &dns_server, &size_dns_server)) == 0)
{
printf("Failed. Error Code ");
}

//printf("%d Bytes empfangen...\n", bytes_received);
//for(count = 0; count < bytes_received; ++count)
//{
//printf("%X ", answer[count]);
//}
//printf("\n");

// IP fest auslesen (Domain Name ist immer gleich lang)
// TODO: Antwort nach dem Protokoll interpretieren
ip[0] = answer[45] & 0xFF;
ip[1] = answer[46] & 0xFF;
ip[2] = answer[47] & 0xFF;
ip[3] = answer[48] & 0xFF;

printf("ptbtime1.ptb.de hat die IP Adresse %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);


close(udb_socket);

return 0;
}

Der Aufruf liefert:

# ./dns
ptbtime1.ptb.de hat die IP Adresse 192.53.103.108

Der DNS Server antwortet mit dem UDP Paket:

UDP Packet ID (from_IP.port-to_IP.port): 212.18.3.5.53-192.168.178.105.50396
45 E 00 . 00 . D5 . B3 . 12 . 00 . 00 . 3D = 11 . 7F . DC . D4 . 12 . 03 . 05 .
C0 . A8 . B2 . 69 i 00 . 35 5 C4 . DC . 00 . C1 . 1F . E5 . AA . AA . 81 . 80 .
00 . 01 . 00 . 01 . 00 . 04 . 00 . 02 . 08 . 70 p 74 t 62 b 74 t 69 i 6D m 65 e
31 1 03 . 70 p 74 t 62 b 02 . 64 d 65 e 00 . 00 . 01 . 00 . 01 . C0 . 0C . 00 .
01 . 00 . 01 . 00 . 00 . 08 . 48 H 00 . 04 . C0 . 35 5 67 g 6C l C0 . 15 . 00 .
02 . 00 . 01 . 00 . 00 . 2D - 96 . 00 . 14 . 06 . 77 w 73 s 2D - 77 w 61 a 73 s
06 . 77 w 69 i 6E n 2D - 69 i 70 p 03 . 64 d 66 f 6E n C0 . 19 . C0 . 15 . 00 .
02 . 00 . 01 . 00 . 00 . 2D - 96 . 00 . 0C . 06 . 75 u 39 9 39 9 31 1 30 0 35 5
02 . 62 b 73 s C0 . 15 . C0 . 15 . 00 . 02 . 00 . 01 . 00 . 00 . 2D - 96 . 00 .
10 . 06 . 69 i 30 0 30 0 30 0 39 9 34 4 06 . 62 b 65 e 72 r 6C l 69 i 6E n C0 .
15 . C0 . 15 . 00 . 02 . 00 . 01 . 00 . 00 . 2D - 96 . 00 . 08 . 05 . 64 d 65 e
6E n 65 e 62 b C0 . 4B K C0 . 75 u 00 . 01 . 00 . 01 . 00 . 00 . 4F O 52 R 00 .
04 . C2 . 5E ^ 5E ^ 5E ^ C0 . 5D ] 00 . 01 . 00 . 01 . 00 . 00 . 09 . 43 C 00 .
04 . C0 . 35 5 67 g 69 i
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SSV-Forum Forum Index >>> DNP/5280 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

SSV Software Systems GmbH

Dünenweg 5
30419 Hannover

Fon: +49(0)511  ·  40 000-0
Fax: +49(0)511  ·  40 000-40

sales@ssv-embedded.de


Impressum    ·    Datenschutz    ·    AGB

© 2023 SSV SOFTWARE SYSTEMS GmbH. Alle Rechte vorbehalten.

ISO 9001:2015