LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Stuck on patching with unified diff file: Kismet on Raspberry Pi (https://www.linuxquestions.org/questions/linux-newbie-8/stuck-on-patching-with-unified-diff-file-kismet-on-raspberry-pi-4175535086/)

Kgeil 02-25-2015 02:49 PM

Stuck on patching with unified diff file: Kismet on Raspberry Pi
 
Hi, I've been trying to get Kismet working nicely on my raspberry pi, and have come across the need to apply a patch that someone posted in the Kismet forums (link and patch are pasted below).

First off, I assume that the patch is created as a text file (GPSPatch.diff) in my case, then applied to the source code using a command like: patch -uNp1 -i GPSPatch.diff

then I recompile using (sudo)
./configure
make
make install
If that's not how to patch a program that's already compiled, if someone can put me on the right path, I'd appreciate it greatly.

Assuming I'm right so far:
When I invoke: patch -uNp1 --dry-run --verbose -i GPSPatch.diff

I get errors. The first seems to just be related to indentation (****malformed patch at [lines not indented])
So, after I fix the indentation, that error goes away, and if I run the command again, I get this:

patch: **** malformed patch at line 11: long aggregate_points;

which I think I can fix with changing (line numbers added by me):

Code:

4 @@ -183,7 +183,7 @@
TO:
Code:

4 @@ -183,9 +183,9 @@
Original code here (line numbers added by me):
Code:

4  @@ -183,7 +183,7 @@
5  double min_lat, min_lon, min_alt, min_spd;
6  double max_lat, max_lon, max_alt, max_spd;
7  // Aggregate/avg center position
8  - long unsigned int add_lat, add_lon, add_alt;
9  + uint64_t add_lat, add_lon, add_alt;
10 double aggregate_lat, aggregate_lon, aggregate_alt;
11 long aggregate_points;
12 };
13 diff -Naur orig/util.cc new/util.cc
14 --- orig/util.cc 2013-03-27 15:41:48.000000000 +0100
15 +++ new/util.cc 2014-05-25 12:54:54.000000000 +0200
16 @@ -1093,11 +1093,11 @@

I am surprised that the patch writer didn't see this though: Is my correction right?

SO, once I get the first two errors to go away, I get this:

**** malformed patch at line 13: diff -Naur orig/util.cc new/util.cc
which refers to this line:
diff -Naur orig/util.cc new/util.cc

Is this because I need to break this patch up into individual files before applying them?

It seems like it, but I'd like to know if there's an easier way. From what little I know about Linux, it always seems like there's an easier way... Thanks as always to anyone who offers assistance!

Kevin





The Link:
https://www.kismetwireless.net/Forum...1016156.530417
The patch contained in the link:
This patch fixes the problem by using a bigger integer type. Verified on a raspberry pi but the problem should be present on all plattforms where 32-bit integers actually are 32-bit. The comments regarding number range is not corrected.
Code:

  1. diff -Naur orig/gpscore.h new/gpscore.h

  2. --- orig/gpscore.h 2013-03-27 15:41:48.000000000 +0100

  3. +++ new/gpscore.h 2014-05-25 12:55:15.000000000 +0200

  4. @@ -183,7 +183,7 @@

  5. double min_lat, min_lon, min_alt, min_spd;

  6. double max_lat, max_lon, max_alt, max_spd;

  7. // Aggregate/avg center position

  8. - long unsigned int add_lat, add_lon, add_alt;

  9. + uint64_t add_lat, add_lon, add_alt;

  10. double aggregate_lat, aggregate_lon, aggregate_alt;

  11. long aggregate_points;

  12. };

  13. diff -Naur orig/util.cc new/util.cc

  14. --- orig/util.cc 2013-03-27 15:41:48.000000000 +0100

  15. +++ new/util.cc 2014-05-25 12:54:54.000000000 +0200

  16. @@ -1093,11 +1093,11 @@

  17. /* Airware PPI gps conversion code from Johnny Csh */

  18. /*

  19. - * input: a unsigned 32-bit (native endian) value between 0 and 3600000000 (inclusive)

  20. + * input: a unsigned 64-bit (native endian) value between 0 and 3600000000 (inclusive)

  21. * output: a signed floating point value betwen -180.0000000 and + 180.0000000, inclusive)

  22. */

  23. -double fixed3_7_to_double(u_int32_t in) {

  24. - int32_t remapped_in = in - (180 * 10000000);

  25. +double fixed3_7_to_double(u_int64_t in) {

  26. + int64_t remapped_in = in - (180 * 10000000);

  27. double ret = (double) ((double) remapped_in / 10000000);

  28. return ret;

  29. }

  30. @@ -1105,16 +1105,16 @@

  31. * input: a native 32 bit unsigned value between 0 and 999999999

  32. * output: a positive floating point value between 000.0000000 and 999.9999999

  33. */

  34. -double fixed3_6_to_double(u_int32_t in) {

  35. +double fixed3_6_to_double(u_int64_t in) {

  36. double ret = (double) in / 1000000.0;

  37. return ret;

  38. }

  39. /*

  40. - * input: a native 32 bit unsigned value between 0 and 999.999999

  41. + * input: a native 64 bit unsigned value between 0 and 999.999999

  42. * output: a signed floating point value between -180000.0000 and +180000.0000

  43. */

  44. -double fixed6_4_to_double(u_int32_t in) {

  45. - int32_t remapped_in = in - (180000 * 10000);

  46. +double fixed6_4_to_double(u_int64_t in) {

  47. + int64_t remapped_in = in - (180000 * 10000);

  48. double ret = (double) ((double) remapped_in / 10000);

  49. return ret;

  50. }

  51. @@ -1130,38 +1130,38 @@

  52. /*

  53. * input: a signed floating point value betwen -180.0000000 and + 180.0000000, inclusive)

  54. - * output: a unsigned 32-bit (native endian) value between 0 and 3600000000 (inclusive)

  55. + * output: a unsigned 64-bit (native endian) value between 0 and 3600000000 (inclusive)

  56. */

  57. -u_int32_t double_to_fixed3_7(double in)

  58. +u_int64_t double_to_fixed3_7(double in)

  59. {

  60. - if (in < -180 || in >= 180)

  61. + if (in < -180 || in >= 180)

  62. return 0;

  63. //This may be positive or negative.

  64. - int32_t scaled_in = (int32_t) ((in) * (double) 10000000);

  65. + int64_t scaled_in = (int64_t) ((in) * (double) 10000000);

  66. //If the input conditions are met, this will now always be positive.

  67. - u_int32_t ret = (u_int32_t) (scaled_in + ((int32_t) 180 * 10000000));

  68. + u_int64_t ret = (u_int64_t) (scaled_in + ((int64_t) 180 * 10000000));

  69. return ret;

  70. }

  71. /*

  72. * input: a signed floating point value betwen -180000.0000 and + 180000.0000, inclusive)

  73. - * output: a unsigned 32-bit (native endian) value between 0 and 3600000000 (inclusive)

  74. + * output: a unsigned 64-bit (native endian) value between 0 and 3600000000 (inclusive)

  75. */

  76. -u_int32_t double_to_fixed6_4(double in)

  77. +u_int64_t double_to_fixed6_4(double in)

  78. {

  79. - if (in < -180000.0001 || in >= 180000.0001)

  80. + if (in < -180000.0001 || in >= 180000.0001)

  81. return 0;

  82. //This may be positive or negative.

  83. - int32_t scaled_in = (int32_t) ((in) * (double) 10000);

  84. + int64_t scaled_in = (int64_t) ((in) * (double) 10000);

  85. //If the input conditions are met, this will now always be positive.

  86. - u_int32_t ret = (u_int32_t) (scaled_in + ((int32_t) 180000 * 10000));

  87. + u_int64_t ret = (u_int64_t) (scaled_in + ((int64_t) 180000 * 10000));

  88. return ret;

  89. }

  90. /*

  91. * input: a positive floating point value between 000.0000000 and 999.9999999

  92. * output: a native 32 bit unsigned value between 0 and 999999999

  93. */

  94. -u_int32_t double_to_fixed3_6(double in) {

  95. - u_int32_t ret = (u_int32_t) (in * (double) 1000000.0);

  96. +u_int64_t double_to_fixed3_6(double in) {

  97. + u_int64_t ret = (u_int64_t) (in * (double) 1000000.0);

  98. return ret;

  99. }

  100. diff -Naur orig/util.h new/util.h

  101. --- orig/util.h 2013-03-27 15:41:48.000000000 +0100

  102. +++ new/util.h 2014-05-25 12:54:54.000000000 +0200

  103. @@ -236,13 +236,13 @@

  104. * the fixedX_Y fixed point values into 'native' doubles for displaying.

  105. * Documentation on these formats can be found in the PPI-GEOLOCATION specification

  106. */

  107. -double fixed3_7_to_double(u_int32_t in);

  108. -double fixed3_6_to_double(u_int32_t in);

  109. -double fixed6_4_to_double(u_int32_t in);

  110. +double fixed3_7_to_double(u_int64_t in);

  111. +double fixed3_6_to_double(u_int64_t in);

  112. +double fixed6_4_to_double(u_int64_t in);

  113. -u_int32_t double_to_fixed3_7(double in);

  114. -u_int32_t double_to_fixed3_6(double in);

  115. -u_int32_t double_to_fixed6_4(double in);

  116. +u_int64_t double_to_fixed3_7(double in);

  117. +u_int64_t double_to_fixed3_6(double in);

  118. +u_int64_t double_to_fixed6_4(double in);

  119. /*

  120. * Some values are encoded as 32-bit unsigned nano-second counters.



norobro 02-25-2015 03:51 PM

See the last paragraph here

So just add a space to the lines common to both files.

Kgeil 02-25-2015 05:04 PM

Hmm, I'm afraid I'm going to need a bit more explanation than that.

Kevin

norobro 02-25-2015 08:25 PM

Sorry. That was a bit of a drive by as I didn't have much time.

AFAIK the format of the patch file has to exactly match the format of the file being patched. All lines that do not begin with +, - or @ have to have a space in the first column. In copy/pasting from a browser you lose all of the white space formating at the beginning of lines.

I don't have access to the source files but when I paste the file from the forum into an editor the line being changed in gpscore.h has a tab after the +/- sign. A tab is not a space, so if the lines above and below the change have tabs, you need a space and then a tab on those lines.

Quote:

Is this because I need to break this patch up into individual files before applying them?
You should be able to do all of the patching from one file.

Code:

@@ -183,7 +183,7 @@
The "7" is the number of lines affected. three lines above, three lines below and the line being changed.

rknichols 02-25-2015 08:36 PM

Try including the "-l" option on the patch command. From the manpage:
-l or --ignore-whitespace
Match patterns loosely, in case tabs or spaces have been munged in your files. Any sequence of one or more blanks in the patch file matches any sequence in the original file, and sequences of blanks at the ends of lines are ignored. Normal characters must still match exactly. Each line of the context must still match a line in the original file.
You may still need a proper space at the beginning of each line that does not begin with "+ " or "- ".

Kgeil 02-26-2015 05:58 AM

Ha! Thank you very much for elaborating Norobro. That's very helpful. rknichols, thanks also for the tip. Unfortunately, I won't get back to this one until the evening, but I feel like I now have enough to go on so that I can apply this patch properly. I'd hate to resort to brute force when I know there is a higher path to learn.


Thanks again!

Kevin

Kgeil 02-26-2015 06:47 AM

OK, I couldn't help but give it a quick try this morning. I edited with vim, and made sure all the spaces were in their proper places, but it still fails at the second diff statement with:
Code:

patch: **** malformed patch at line 13: diff -Naur orig/util.cc new/util.cc
The file util.cc exists in the proper directory (same as the first diff statement), and the lines referenced do match, but it fails right on line 13.

Am I missing something on what needs to happen when the second diff line is called?

Thanks,

Kevin

rknichols 02-26-2015 09:21 AM

patch should just ignore that line 13 as "trailing garbage" after the successful first patch. I see you are using the "--verbose" option. Was anything reported besides the error?

norobro 02-26-2015 09:50 AM

1 Attachment(s)
Thanks for the -l tip @rknichols. I need to read man pages more thouroghly.

Kevin, I downloaded the kismet source and got the attached patch file to work. It is only for the first two files (gpscore.h and util.cc).

Using:
Code:

patch -p1 -l -i partialpatch.diff
Experimenting, I found that you do need either a space or a tab (or both) as the first character on lines common to both files. If just a space is used it works with a warning(?) "Hunk #1 succeeded at 183 with fuzz 1."

Also, in testing I found that the patch fails if you do not have a space (or tab) after the +/- sign if the original file has a space or tab. Edit 2: Never mind. I tried so many combinations I confused myself.

HTH

Norm

Edit: Forum will not accept a file with diff as extension.

Kgeil 02-26-2015 05:08 PM

Wow, thank you very much Norm! I just tried the partial, and it should give me the basis I need to make this thing work. Thank you again.
I'm always impressed by the helpfulness of others, on this and many other forums. Thank you LQ!!


Now, off to patching; between that, and another hour of reading about patch and diff, I'll be on my way to understanding another facet of Linux administration.

Thanks again,


Kevin


All times are GMT -5. The time now is 08:16 AM.