7 #include <netinet/in.h>
11 #include "signature.h"
15 static unsigned char lead_magic[] = {
16 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
19 /* The lead needs to be 8 byte aligned */
21 rpmRC writeLead(FD_t fd, const struct rpmlead *lead)
25 memcpy(&l, lead, sizeof(l));
27 memcpy(&l.magic, lead_magic, sizeof(l.magic));
28 l.type = htons(l.type);
29 l.archnum = htons(l.archnum);
30 l.osnum = htons(l.osnum);
31 l.signature_type = htons(l.signature_type);
33 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
39 rpmRC readLead(FD_t fd, struct rpmlead *lead)
41 memset(lead, 0, sizeof(*lead));
42 /* FIX: remove timed read */
43 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
45 rpmlog(RPMERR_READ, _("read failed: %s (%d)\n"),
46 Fstrerror(fd), errno);
49 return RPMRC_NOTFOUND;
52 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic)))
53 return RPMRC_NOTFOUND;
54 lead->type = ntohs(lead->type);
55 lead->archnum = ntohs(lead->archnum);
56 lead->osnum = ntohs(lead->osnum);
57 lead->signature_type = ntohs(lead->signature_type);
58 if (lead->signature_type != RPMSIGTYPE_HEADERSIG)
59 return RPMRC_NOTFOUND;